/**   
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-07 13:44:19  
 * Copyright (c) 2015- joysuch-版权所有     
 */

package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpEmergencyMaterialType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * BpEmergencyMaterialTypeDao
 * 
 */
public interface BpEmergencyMaterialTypeDao
        extends JpaRepository<BpEmergencyMaterialType, Long>, QuerydslPredicateExecutor<BpEmergencyMaterialType> {
    public Page<BpEmergencyMaterialType> findAll(Specification<BpEmergencyMaterialType> spec, Pageable pageable);

    public BpEmergencyMaterialType save(BpEmergencyMaterialType bean);

    public void delete(BpEmergencyMaterialType bean);

    // 查询是否有指定名称的物资类型
    public Integer countByName(String name);

    @Modifying
    @Query("update BpEmergencyMaterialType t set materialCount=(select count(m) from BpEmergencyMaterial m where m.materialTypeId=t.id) where t.id=?1")
    void updateMaterialCount(Long id);
}
